<?php
function bend_lov(&$retparams){
	global $_db;
	
	if(!isset($_POST['op'])){
		return BEND_REDIRECT;
	}
	elseif("addview"==$_POST['op']){
		echo rendertpl("applet/lovaddmod.applet");
		return BEND_RENDERED;
	}
	elseif("add"==$_POST['op']){
		$desc = $_POST['desc'];
		$id = $_db->insert("lov", array("type"=>$_POST['type'], "name"=>$_POST['name'], "val"=>$_POST['val'], "desc"=>$_POST['desc'],"seq"=>$_POST['seq'],"default"=>$_POST['default']));
		if($id>0){
			$retparams['errorcode'] = 0;
		}
		else{
			$retparams['errorcode'] = -1;
		}
		return BEND_ECHORET;
	}
	elseif("del"==$_POST['op']){
		$count = $_db->delete("lov", "id=$_POST[id]");
	}
	elseif("modview"==$_POST['op']){
		echo rendertpl("applet/lovaddmod.applet");
		return BEND_RENDERED;
	}
	elseif("mod"==$_POST['op']){//不能修改type, name
		$count = $_db->update("lov", array("val"=>$_POST['val'], "desc"=>$_POST['desc'],"seq"=>$_POST['seq'],"default"=>$_POST['default']),"id=$_POST[id]");
		if($count>0){
			$retparams['errorcode'] = 0;
		}
		else{
			$retparams['errorcode'] = -1;
		}
		return BEND_ECHORET;
	}
	elseif("search"==$_POST['op']){
		return BEND_HOMEPAGE;
	}
	return BEND_REDIRECT;
}
?>